<?php

define('IN_API', true);
require_once '../../framework/bootstrap.inc.php';
require_once 'defines.php';

$id = $_GPC['id'];
$settings = pdo_get("uni_account_modules", array("module" => MODULE_NAME , "uniacid" => $id));
$settings = unserialize($settings['settings']);

$lasttime = strtotime(date('Y-m-d',strtotime(date('Y-m-1').'-1 day')))+86400;
if($settings['system_type'] == 1){
	$condition = " WHERE system_id = ".$settings['system_id'];
	$condition .= " AND (c_1_uid > 0 or c_2_uid > 0 or c_3_uid > 0 or c_t_uid > 0 or c_2t_uid > 0 or c_1h_uid > 0 or c_2h_uid > 0 or c_3h_uid > 0 or c_4h_uid > 0) AND (order_status = 8 || order_status = 103) AND order_paid_time <= ".$lasttime . " AND (pingtai = 'meituan'  OR pingtai = 'movie'  OR pingtai = 'fenxiao' OR pingtai = 'jutuike') AND (pingtai_name = '美团外卖'  OR pingtai_name = '美团闪购'  OR pingtai_name = '美团团购' OR pingtai_name = '美团酒店' OR pingtai_name = '美团优选' OR pingtai_name = '电影票' OR pingtai_name = '肯德基' OR pingtai_name = '麦当劳' OR pingtai_name = '其他' OR pingtai_name = '分销联盟' OR pingtai_name = '') AND order_settlement_time = 0";

	$orderby = " ORDER BY id ASC ";

	$list = pdo_fetchall("SELECT * FROM " . tablename(MODULE_NAME."_order_u") . $condition . $orderby);

	foreach ($list as $key => $val) {
		if($val['c_1_uid']){
			pdo_update(MODULE_NAME."_user_u", array('money +=' => $val['c_1'],'credit +=' => round($settings['credit_order_rate'] * $val['c_1'],0)), array("uid" => $val['c_1_uid'], "system_id" => $settings['system_id']));
			$user = pdo_get(MODULE_NAME."_user_u", array("uid" => $val['c_1_uid'], "system_id" => $settings['system_id']));
			$result = pdo_insert(MODULE_NAME."_user_logs_u", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => $val['c_1'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_1'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => round($settings['credit_order_rate'] * $val['c_1'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_1'],0), "order_id" => $val['order_id']));
			
		}
		if($val['c_2_uid']){
			pdo_update(MODULE_NAME."_user_u", array('money +=' => $val['c_2'],'credit +=' => round($settings['credit_order_rate'] * $val['c_2'],0)), array("uid" => $val['c_2_uid'], "system_id" => $settings['system_id']));
			$user = pdo_get(MODULE_NAME."_user_u", array("uid" => $val['c_2_uid'], "system_id" => $settings['system_id']));
			$result = pdo_insert(MODULE_NAME."_user_logs_u", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => $val['c_2'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_2'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => round($settings['credit_order_rate'] * $val['c_2'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_2'],0), "order_id" => $val['order_id']));
			
		}

		if($val['c_3_uid']){
			pdo_update(MODULE_NAME."_user_u", array('money +=' => $val['c_3'],'credit +=' => round($settings['credit_order_rate'] * $val['c_3'],0)), array("uid" => $val['c_3_uid'], "system_id" => $settings['system_id']));
			$user = pdo_get(MODULE_NAME."_user_u", array("uid" => $val['c_3_uid'],"uniacid" => $id));
			$result = pdo_insert(MODULE_NAME."_user_logs_u", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => $val['c_3'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_3'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => round($settings['credit_order_rate'] * $val['c_3'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_3'],0), "order_id" => $val['order_id']));
			
		}
		if($val['c_t_uid']){
			pdo_update(MODULE_NAME."_user_u", array('money +=' => $val['c_t'],'credit +=' => round($settings['credit_order_rate'] * $val['c_t'],0)), array("uid" => $val['c_t_uid'], "system_id" => $settings['system_id']));
			$user = pdo_get(MODULE_NAME."_user_u", array("uid" => $val['c_t_uid'], "system_id" => $settings['system_id']));
			$result = pdo_insert(MODULE_NAME."_user_logs_u", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => $val['c_t'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_t'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => round($settings['credit_order_rate'] * $val['c_t'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_t'],0), "order_id" => $val['order_id']));
			
		}
		if($val['c_2t_uid']){
			pdo_update(MODULE_NAME."_user_u", array('money +=' => $val['c_2t'],'credit +=' => round($settings['credit_order_rate'] * $val['c_2t'],0)), array("uid" => $val['c_2t_uid'], "system_id" => $settings['system_id']));
			$user = pdo_get(MODULE_NAME."_user_u", array("uid" => $val['c_2t_uid'], "system_id" => $settings['system_id']));
			$result = pdo_insert(MODULE_NAME."_user_logs_u", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => $val['c_2t'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_2t'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => round($settings['credit_order_rate'] * $val['c_2t'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_2t'],0), "order_id" => $val['order_id']));
			
		}
		if($val['c_1h_uid']){
			pdo_update(MODULE_NAME."_user_u", array('money +=' => $val['c_1h'],'credit +=' => round($settings['credit_order_rate'] * $val['c_1h'],0)), array("uid" => $val['c_1h_uid'], "system_id" => $settings['system_id']));
			$user = pdo_get(MODULE_NAME."_user_u", array("uid" => $val['c_1h_uid'], "system_id" => $settings['system_id']));
			$result = pdo_insert(MODULE_NAME."_user_logs_u", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => $val['c_1h'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_1h'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => round($settings['credit_order_rate'] * $val['c_1h'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_1h'],0), "order_id" => $val['order_id']));
			

		}
		if($val['c_2h_uid']){
			pdo_update(MODULE_NAME."_user_u", array('money +=' => $val['c_2h'],'credit +=' => round($settings['credit_order_rate'] * $val['c_2h'],0)), array("uid" => $val['c_2h_uid'], "system_id" => $settings['system_id']));
			$user = pdo_get(MODULE_NAME."_user_u", array("uid" => $val['c_2h_uid'], "system_id" => $settings['system_id']));
			$result = pdo_insert(MODULE_NAME."_user_logs_u", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => $val['c_2h'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_2h'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => round($settings['credit_order_rate'] * $val['c_2h'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_2h'],0), "order_id" => $val['order_id']));
			

		}
		if($val['c_3h_uid']){
			pdo_update(MODULE_NAME."_user_u", array('money +=' => $val['c_3h'],'credit +=' => round($settings['credit_order_rate'] * $val['c_3h'],0)), array("uid" => $val['c_3h_uid'], "system_id" => $settings['system_id']));
			$user = pdo_get(MODULE_NAME."_user_u", array("uid" => $val['c_3h_uid'], "system_id" => $settings['system_id']));
			$result = pdo_insert(MODULE_NAME."_user_logs_u", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => $val['c_3h'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_3h'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => round($settings['credit_order_rate'] * $val['c_3h'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_3h'],0), "order_id" => $val['order_id']));
			
		}
		if($val['c_4h_uid']){
			pdo_update(MODULE_NAME."_user_u", array('money +=' => $val['c_4h'],'credit +=' => round($settings['credit_order_rate'] * $val['c_4h'],0)), array("uid" => $val['c_4h_uid'], "system_id" => $settings['system_id']));
			$user = pdo_get(MODULE_NAME."_user_u", array("uid" => $val['c_4h_uid'], "system_id" => $settings['system_id']));
			$result = pdo_insert(MODULE_NAME."_user_logs_u", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => $val['c_4h'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_4h'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'],"uniacid" => $id, "system_id" => $settings['system_id'], "num" => round($settings['credit_order_rate'] * $val['c_4h'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_4h'],0), "order_id" => $val['order_id']));
			

		}
		pdo_update(MODULE_NAME."_order_u", array('order_settlement_time' => time()), array("id" => $val['id'], "system_id" => $settings['system_id']));

	}
}else{
	$condition = " WHERE uniacid = ".$id;
	$condition .= " AND (c_1_uid > 0 or c_2_uid > 0 or c_3_uid > 0 or c_t_uid > 0 or c_2t_uid > 0 or c_1h_uid > 0 or c_2h_uid > 0 or c_3h_uid > 0 or c_4h_uid > 0) AND (order_status = 8 || order_status = 103) AND order_paid_time <= ".$lasttime . " AND (pingtai = 'meituan'  OR pingtai = 'movie'  OR pingtai = 'fenxiao' OR pingtai = 'jutuike') AND (pingtai_name = '美团外卖'  OR pingtai_name = '美团闪购'  OR pingtai_name = '美团团购' OR pingtai_name = '美团酒店' OR pingtai_name = '美团优选' OR pingtai_name = '电影票' OR pingtai_name = '肯德基' OR pingtai_name = '麦当劳' OR pingtai_name = '其他' OR pingtai_name = '分销联盟' OR pingtai_name = '') AND order_settlement_time = 0";

	$orderby = " ORDER BY id ASC ";

	$list = pdo_fetchall("SELECT * FROM " . tablename(MODULE_NAME."_order") . $condition . $orderby);

	foreach ($list as $key => $val) {
		if($val['c_1_uid']){
			pdo_update(MODULE_NAME."_user", array('money +=' => $val['c_1'],'credit +=' => round($settings['credit_order_rate'] * $val['c_1'],0)), array("uid" => $val['c_1_uid'],"uniacid" => $id));
			$user = pdo_get(MODULE_NAME."_user", array("uid" => $val['c_1_uid'],"uniacid" => $id));
			$result = pdo_insert(MODULE_NAME."_user_logs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'], "uniacid" => $id, "num" => $val['c_1'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_1'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"uniacid" => $id, "num" => round($settings['credit_order_rate'] * $val['c_1'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_1'],0), "order_id" => $val['order_id']));
			
		}
		if($val['c_2_uid']){
			pdo_update(MODULE_NAME."_user", array('money +=' => $val['c_2'],'credit +=' => round($settings['credit_order_rate'] * $val['c_2'],0)), array("uid" => $val['c_2_uid'],"uniacid" => $id));
			$user = pdo_get(MODULE_NAME."_user", array("uid" => $val['c_2_uid'],"uniacid" => $id));
			$result = pdo_insert(MODULE_NAME."_user_logs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'], "uniacid" => $id, "num" => $val['c_2'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_2'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"uniacid" => $id, "num" => round($settings['credit_order_rate'] * $val['c_2'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_2'],0), "order_id" => $val['order_id']));
			
		}

		if($val['c_3_uid']){
			pdo_update(MODULE_NAME."_user", array('money +=' => $val['c_3'],'credit +=' => round($settings['credit_order_rate'] * $val['c_3'],0)), array("uid" => $val['c_3_uid'],"uniacid" => $id));
			$user = pdo_get(MODULE_NAME."_user", array("uid" => $val['c_3_uid'],"uniacid" => $id));
			$result = pdo_insert(MODULE_NAME."_user_logs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'], "uniacid" => $id, "num" => $val['c_3'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_3'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"uniacid" => $id, "num" => round($settings['credit_order_rate'] * $val['c_3'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_3'],0), "order_id" => $val['order_id']));
			
		}
		if($val['c_t_uid']){
			pdo_update(MODULE_NAME."_user", array('money +=' => $val['c_t'],'credit +=' => round($settings['credit_order_rate'] * $val['c_t'],0)), array("uid" => $val['c_t_uid'],"uniacid" => $id));
			$user = pdo_get(MODULE_NAME."_user", array("uid" => $val['c_t_uid'],"uniacid" => $id));
			$result = pdo_insert(MODULE_NAME."_user_logs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'], "uniacid" => $id, "num" => $val['c_t'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_t'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"uniacid" => $id, "num" => round($settings['credit_order_rate'] * $val['c_t'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_t'],0), "order_id" => $val['order_id']));
			
		}
		if($val['c_2t_uid']){
			pdo_update(MODULE_NAME."_user", array('money +=' => $val['c_2t'],'credit +=' => round($settings['credit_order_rate'] * $val['c_2t'],0)), array("uid" => $val['c_2t_uid'],"uniacid" => $id));
			$user = pdo_get(MODULE_NAME."_user", array("uid" => $val['c_2t_uid'],"uniacid" => $id));
			$result = pdo_insert(MODULE_NAME."_user_logs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'], "uniacid" => $id, "num" => $val['c_2t'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_2t'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"uniacid" => $id, "num" => round($settings['credit_order_rate'] * $val['c_2t'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_2t'],0), "order_id" => $val['order_id']));
			
		}
		if($val['c_1h_uid']){
			pdo_update(MODULE_NAME."_user", array('money +=' => $val['c_1h'],'credit +=' => round($settings['credit_order_rate'] * $val['c_1h'],0)), array("uid" => $val['c_1h_uid'],"uniacid" => $id));
			$user = pdo_get(MODULE_NAME."_user", array("uid" => $val['c_1h_uid'],"uniacid" => $id));
			$result = pdo_insert(MODULE_NAME."_user_logs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'], "uniacid" => $id, "num" => $val['c_1h'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_1h'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"uniacid" => $id, "num" => round($settings['credit_order_rate'] * $val['c_1h'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_1h'],0), "order_id" => $val['order_id']));
			
		}
		if($val['c_2h_uid']){
			pdo_update(MODULE_NAME."_user", array('money +=' => $val['c_2h'],'credit +=' => round($settings['credit_order_rate'] * $val['c_2h'],0)), array("uid" => $val['c_2h_uid'],"uniacid" => $id));
			$user = pdo_get(MODULE_NAME."_user", array("uid" => $val['c_2h_uid'],"uniacid" => $id));
			$result = pdo_insert(MODULE_NAME."_user_logs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'], "uniacid" => $id, "num" => $val['c_2h'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_2h'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"uniacid" => $id, "num" => round($settings['credit_order_rate'] * $val['c_2h'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_2h'],0), "order_id" => $val['order_id']));
			
		}
		if($val['c_3h_uid']){
			pdo_update(MODULE_NAME."_user", array('money +=' => $val['c_3h'],'credit +=' => round($settings['credit_order_rate'] * $val['c_3h'],0)), array("uid" => $val['c_3h_uid'],"uniacid" => $id));
			$user = pdo_get(MODULE_NAME."_user", array("uid" => $val['c_3h_uid'],"uniacid" => $id));
			$result = pdo_insert(MODULE_NAME."_user_logs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'], "uniacid" => $id, "num" => $val['c_3h'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_3h'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"uniacid" => $id, "num" => round($settings['credit_order_rate'] * $val['c_3h'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_3h'],0), "order_id" => $val['order_id']));
			
		}
		if($val['c_4h_uid']){
			pdo_update(MODULE_NAME."_user", array('money +=' => $val['c_4h'],'credit +=' => round($settings['credit_order_rate'] * $val['c_4h'],0)), array("uid" => $val['c_4h_uid'],"uniacid" => $id));
			$user = pdo_get(MODULE_NAME."_user", array("uid" => $val['c_4h_uid'],"uniacid" => $id));
			$result = pdo_insert(MODULE_NAME."_user_logs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"unionid" => $user['unionid'], "uniacid" => $id, "num" => $val['c_4h'], "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['money']-$val['c_4h'], "order_id" => $val['order_id']));
			$result = pdo_insert(MODULE_NAME."_user_creditlogs", array("user_id" => $user['user_id'],"openid" => $user['openid'],"uniacid" => $id, "num" => round($settings['credit_order_rate'] * $val['c_4h'],0), "create_time" => $_W["timestamp"], "reason" => '订单结算', "last_num" => $user['credit']-round($settings['credit_order_rate'] * $val['c_4h'],0), "order_id" => $val['order_id']));
			
		}
		pdo_update(MODULE_NAME."_order", array('order_settlement_time' => time()), array("id" => $val['id'],"uniacid" => $id));

	}

}

